﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCCHWLib.Commands
{
    public class DeAllocateCommand:ICommand
    {

        public DeAllocateCommand(object paramter, ParameterType paramterType)
        {
            m_Operand1 = paramter;
            m_Type1 = paramterType;
            m_ExOperand1 = paramter;
            m_ExType1 = paramterType;
        }
        public override object Execute(Processor processor)
        {
            int address = Convert.ToInt32(m_ExOperand1);
            string key = null;
            int size = 1;
            foreach (string x in Processor.GlobalLiteralTable.Keys)
            {
                if (Processor.GlobalLiteralTable[x].Address == address)
                {
                    key = x;
                    size = Processor.GlobalLiteralTable[x].Size;
                }
            }
            processor.Cache.Deallocate(address,size);
            Processor.GlobalLiteralTable.Remove(key);
            return null;
        }

        public override string ToString()
        {
            return String.Format("DEALLOC ( {0} )", m_Operand1);
        }
    }
}
